package com.twelve.controller.faker;

import com.github.javafaker.Faker;
import com.twelve.bean.faker.Recently1;
import com.twelve.utils.JqgridUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * @program: twelve
 * @description: 超标采购
 * @author: geyuqi
 * @create: 2018-11-27 17:54
 **/
@Controller
@RequestMapping("/overproof")
public class OverproofController {


    private Faker faker = new Faker(Locale.CHINA);

    @Resource
    private JqgridUtil jqgridUtil;

    /**
     * 跳转页面
     * @param request
     * @return
     */
    @RequestMapping("")
    public String recently(HttpServletRequest request){
        return "faker/overproof";
    }

    /**
     * 超标列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public String list(HttpServletRequest request){
        String pageNo = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数
        String pageSize = request.getParameter("rows"); // 取得每页显示行数，,注意这是jqgrid自身的参数

        List<Recently1> list = new ArrayList<Recently1>();
        for (int i = 0; i < 12; i++) {
            Recently1 recently1 = new Recently1();
            recently1.setAreaDeptName(faker.address().cityName());
            if (i == 0) {
                recently1.setContent("注浆泵活塞采购价格超标,原范围2750~2850, 采购价3035");
            }else if(i==1){
                recently1.setContent("缓冲托辊采购价格超标，原范围500~520,采购价600");
            }else if(i==2){
                recently1.setContent("安全帽采购价格超标,原范围15-25.采购价100");
            }
            if (i == 3) {
                recently1.setContent("注浆泵活塞采购价格超标,原范围2750~2850, 采购价3035");
            }else if(i==4){
                recently1.setContent("缓冲托辊采购价格超标，原范围500~520,采购价600");
            }else if(i==5){
                recently1.setContent("安全帽采购价格超标,原范围15-25.采购价100");
            }
            if (i == 6) {
                recently1.setContent("注浆泵活塞采购价格超标,原范围2750~2850, 采购价3035");
            }else if(i==7){
                recently1.setContent("缓冲托辊采购价格超标，原范围500~520,采购价600");
            }else if(i==8){
                recently1.setContent("安全帽采购价格超标,原范围15-25.采购价100");
            }
            if (i == 9) {
                recently1.setContent("注浆泵活塞采购价格超标,原范围2750~2850, 采购价3035");
            }else if(i==10){
                recently1.setContent("缓冲托辊采购价格超标，原范围500~520,采购价600");
            }else if(i==11){
                recently1.setContent("安全帽采购价格超标,原范围15-25.采购价100");
            }

            recently1.setName(faker.name().name());
            recently1.setTime(DateFormat.getDateTimeInstance().format(new Date()));
            list.add(recently1);
        }

        return jqgridUtil.getJson(list, pageNo, 10 , 10);
    }
}
